package org.zcl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.zcl.dao.TbUnionMapper;
import org.zcl.entity.TbUnion;
import org.zcl.service.TbUnion2Service;
import org.zcl.service.TbUnionService;

import java.util.List;

/**
 * 工会表(TbUnion)表服务实现类
 *
 * @author Chenglin Zhu
 * @since 2022-01-06 16:28:47
 */
@Service("tbUnionService")
public class TbUnionServiceImpl extends ServiceImpl<TbUnionMapper, TbUnion> implements TbUnionService {

    @Autowired
    private TbUnion2Service tbUnion2Service;

    @Override
    public Boolean insertUnion(TbUnion tbUnion) {
        return this.save(tbUnion);
    }

    @Override
    public List<TbUnion> getUnionList() {
        LambdaQueryWrapper<TbUnion> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.gt(TbUnion::getId, 4);
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void addTbUnionTransactionalRequired(TbUnion tbUnion) throws Exception {
        // 方法1调用方法2，异常一起回滚
        this.baseMapper.insert(tbUnion);
        tbUnion2Service.addTbUnionTransactionalException(tbUnion);

    }
}

